﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using EkejiWeb.Model;
using EkejiWeb.BLL;

namespace EkejiWeb.Web.Admin.AdminUser
{
    public partial class Edit : System.Web.UI.Page
    {
        AdminModel model = new AdminModel();
        AdminBLL bll = new AdminBLL();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                NewMethod();
            }
        }
        private void NewMethod()
        {
            int id = int.Parse(Request["id"]);
            DataSet ds = bll.SelectAdminByID(id);
            if (ds.Tables[0].Rows.Count > 0)
            {
                userid.Text = ds.Tables[0].Rows[0]["ID"].ToString();
                user.Text = ds.Tables[0].Rows[0]["UserName"].ToString();
                password.Text = ds.Tables[0].Rows[0]["Password"].ToString();
                tbType.SelectedItem.Text = ds.Tables[0].Rows[0]["Type"].ToString();
                idcard.Text = ds.Tables[0].Rows[0]["IdCard"].ToString();
                Tel.Text = ds.Tables[0].Rows[0]["Tel"].ToString();
                QQ.Text = ds.Tables[0].Rows[0]["QQ"].ToString();
                address.Text = ds.Tables[0].Rows[0]["Adress"].ToString();
            }
        }

        protected void rightsub_Click(object sender, EventArgs e)
        {
            bool flag = false;

            model.ID = int.Parse(Request["id"]);
            model.UserName = user.Text.Trim();
            model.PassWord = password.Text.Trim();
            model.IdCard = idcard.Text.Trim();
            model.Type = tbType.SelectedItem.Text.Trim();
            model.Tel = Tel.Text.Trim();
            model.QQ = QQ.Text.Trim();
            model.Adress = address.Text.Trim();

            flag = bll.Update(model);
            if (flag)
            {
                Response.Write("<Script Language=JavaScript>alert('修改成功！');</Script>");
                return;
            }
            else
            {
                Response.Write("<Script Language=JavaScript>alert('修改失败！');</Script>");
                return;
            }
        }
    }
}